package com.yanqu.road.server.cmd.newmonopolymkt.res;

import com.yanqu.road.entity.enums.eMonopolyMarketResType;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.newmonopolymkt.NewMonopolyMarketProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.command.CmdApi;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.manger.NewMonopolyMarketCommonMgr;
import com.yanqu.road.server.manger.systemgroup.newmonopolymarket.NewMonopolyMarketMgr;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.CrossProtocol;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.GameProtocol;

@CmdApi(reqMsg = NewMonopolyMarketProto.NewMonopolyMarketGetPointRewardReqMsg.class, respMsg = NewMonopolyMarketProto.NewMonopolyMarketGetPointRewardRespMsg.class)
@Cmd(code = GameProtocol.S_NEW_MONOPOLY_MARKET_RES_GRAB_GET_POINT_REWARD, desc = "批量领取资源点")
public class NewMonopolyMarketResGrabGetPointRewardCmd extends AbstractCommand {

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        NewMonopolyMarketProto.NewMonopolyMarketGetPointRewardReqMsg req = NewMonopolyMarketProto.NewMonopolyMarketGetPointRewardReqMsg.parseFrom(packet.getBytes());
        if(!NewMonopolyMarketMgr.canEnterSystem(player)){
            ret = GameErrorCode.E_SYSTEM_NO_OPEN;
            return;
        }
        if(!NewMonopolyMarketCommonMgr.isSystemOpenTime(eMonopolyMarketResType.RES_KING_NEW.getValue())
                && !NewMonopolyMarketCommonMgr.isSystemOpenTime(eMonopolyMarketResType.RES_QUEEN_NEW.getValue())){
            ret = GameErrorCode.E_NEW_MONOPOLY_MARKET_SYSTEM_NO_OPEN;
            return;
        }
        NewMonopolyMarketMgr.sendAppointActivityPacket(player.getUserId(), CrossProtocol.C_CROSS_NEW_MONOPOLY_MARKET_RES_GRAB_GET_POINT_REWARD, req.toBuilder());
    }

    @Override
    public void sendData(GamePlayer player) {
        if (ret != 0) {
            NewMonopolyMarketProto.NewMonopolyMarketGetPointRewardRespMsg.Builder builder = NewMonopolyMarketProto.NewMonopolyMarketGetPointRewardRespMsg.newBuilder();
            builder.setRet(ret);
            player.sendPacket(ClientProtocol.U_NEW_MONOPOLY_MARKET_RES_GRAB_GET_POINT_REWARD, builder);
        }
    }

}
